package com.example.controller;

import com.example.common.Result;
import com.example.entity.Orderinfo;
import com.example.service.OrderinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

@RestController
@RequestMapping("/api/phone")
public class phoneCodeLogin {
    @Autowired
    private OrderinfoService orderinfoService;

    @Autowired
    private JedisPool jedisPool;

    @RequestMapping("/login")
    public Result PhoneLong(String phone,String code){
        String redisCode = jedisPool.getResource().get(phone);
        if (null !=redisCode){
            if (redisCode.equals(code)){
                Orderinfo orderinfo = orderinfoService.showByPhone(phone);
                if (orderinfo !=null){
                    return Result.success();
                }else {
                    return Result.error("5000","请先注册");
                }
            }else {
                return Result.error("5001","验证码错误");
            }
        }
        return Result.error("5002","验证码不存在");
    }

}
